const express = require('express')
const c = require('../connection')
const router = express.Router()
//查询省份列表接口
router.get('/province-list', (req, res) => {
    c.query(`select * from uc_province`, (err, r) => {
        if (err) {
            throw err
        }
        if (r.length > 0) {
            res.send({
                code: 200,
                msg: '省份列表查询成功',
                data: r
            })
        } else {
            res.send({
                code: 401,
                msg: '查询失败'
            })
        }
    })
})
//通过省份编号查询城市列表接口
router.get('/city-list', (req, res) => {
    var obj = req.query
    c.query(`select * from uc_city,uc_province where cityid=province and province=?`, [obj.province], (err, r) => {
        if (err) {
            throw err
        }
        if (r.length > 0) {
            res.send({
                code: 200,
                msg: '城市列表查询成功',
                data: r
            })
        } else {
            res.send({
                code: 401,
                msg: '查询失败'
            })
        }
    })
})
//查询所有车辆品牌
router.get('/car-brand', (req, res) => {
    c.query(`select * from uc_brand`, (err, r) => {
        if (err) {
            throw err
        }
        if (r.length > 0) {
            res.send({
                code: 200,
                msg: '车辆品牌查询成功',
                data: r
            })
        } else {
            res.send({
                code: 401,
                msg: '查询失败'
            })
        }
    })
})
//通过品牌编号查询车系接口
router.get('/car-series', (req, res) => {
    var obj = req.query
    c.query(`select * from uc_brand,uc_car where seriesid=brandname and brandname=?`, [obj.brandname], (err, r) => {
        if (err) {
            throw err
        }
        if (r.length > 0) {
            res.send({
                code: 200,
                msg: '车系车型查询成功',
                data: r
            })
        } else {
            res.send({
                code: 401,
                msg: '查询失败'
            })
        }
    })
})
//查询车辆图片接口
router.get('/car', (req, res) => {
    var obj = req.query
    c.query(`select * from uc_car where carseries=?`, [obj.carseries], (err, r) => {
        if (err) {
            throw err
        }
        if (r.length > 0) {
            res.send({
                code: 200,
                msg: '查询车辆成功',
                data: r
            })
        } else {
            res.send({
                code: 401,
                msg: '查询失败'
            })
        }
    })
})
//查询事故类型接口
router.get('/accident', (req, res) => {
    c.query(`select * from uc_accident`, (err, r) => {
        if (err) {
            throw err
        }
        if (r.length > 0) {
            res.send({
                code: 200,
                msg: '事故类型查询成功',
                data: r
            })
        } else {
            res.send({
                code: 401,
                msg: '查询失败'
            })
        }
    })
})
//查询车辆存放位置接口
router.get('/address', (req, res) => {
    c.query(`select * from uc_address`, (err, r) => {
        if (err) {
            throw err
        }
        if (r.length) {
            res.send({
                code: 200,
                msg: '存放地查询成功',
                data: r
            })
        } else {
            res.send({
                code: 401,
                msg: '查询失败'
            })
        }
    })
})
//查询保险公司类型列表接口
router.get('/insure', (req, res) => {
    c.query(`select * from uc_insure`, (err, r) => {
        if (err) {
            throw err
        }
        if (r.length > 0) {
            res.send({
                code: 200,
                msg: '保险公司列表查询成功',
                data: r
            })
        } else {
            res.send({
                code: 401,
                msg: '查询失败'
            })
        }
    })
})
module.exports = router
